home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 003.dms / 003.adf / TEXT / chapter3.txt < prev    next >
Text File  |  1992-09-02  |  4KB  |  129 lines

  1.  
  2.               The Absolute Beginners Guide To Amos
  3.               -------------------------------------
  4.                          Chapter Three
  5.                          -------------
  6.  
  7.  
  8. In this chapter we will be covering variables, before you start telling 
  9. yourself you`ll never understand variables it`s not half as complicated 
  10. as it first seems.
  11.  
  12. A variable is a letter or combination of letters and numbers that hold a 
  13. numerical value.
  14.  
  15. Read the last paragraph again slowly and try to understand it.  
  16.  
  17. Here are some examples of a variable name:
  18.  
  19. A
  20.  
  21. AA
  22.  
  23. ABC
  24.  
  25. AVARIABLE
  26.  
  27. YETANOTHER
  28.  
  29. F1
  30.  
  31. F1LW4
  32.  
  33.  
  34. I will explain what use variables are to us in a moment so don`t worry
  35. why we use them for now just try and understand how they work.
  36.  
  37. To use a variable we first have to give it a name. 
  38. This can be almost anything as long as it starts with a letter and not a 
  39. number and doesn`t contain spaces, if you want a space you can use the 
  40. underscore charachter _
  41.  
  42. FRED_FLINTSTONE_RULES
  43.  
  44. Another restriction is you must not use keywords, PRINT for example is a 
  45. keyword.  You can use a key word amongst other letters and numbers though
  46. for example:
  47.  
  48. XPRINT5
  49.  
  50.   
  51. OK, let`s call our variable F1, we must now tell Amos what value we
  52. want F1 to hold initially, this is quite straight forward we use the = sign,
  53. and then the value so let us say we want F1 to hold the value of 10:
  54.  
  55. F1=10
  56.  
  57. It`s as straight forward as that.  We can now chop and change the value of F1
  58. very easily from within our program using the INC and DEC commands.
  59.  
  60. INC F1
  61.  
  62. This will add 1 to the current value of F1.  Let`s imagine that we have a
  63. program that counts cars that pass a motorway junction and each time a
  64. car passes we increment our counter by 1.  Our variable (or counter) is F1
  65. and to start off we want F1 to equal 0, as we haven`t started counting yet.
  66. Right we have sat down at our imaginary computer and the first car has 
  67. passed so we have to add 1 to F1 we do this in Amos with INC, as described
  68. earlier,
  69.  
  70. INC F1
  71.  
  72. F1 now equals 1, let`s say we now decide to go for lunch and someone else
  73. takes over our imaginary computer and they would like to know out of 
  74. interest how many cars you counted, in Amos we would do this,
  75.  
  76. PRINT F1
  77.  
  78. Which will PRINT the current value of F1 on the screen, the person would see
  79. that F1 equalled 1 and call you a lazy git.  We will cover the printing of a
  80. variable in the next chapter.
  81.  
  82. DEC is the exact opposite to INC this will subtract 1 from F1 like this,
  83.  
  84. F1=1
  85. DEC F1
  86. PRINT F1
  87.  
  88. Do you know what the answer would be? That is right, 0.
  89. If F1 equalled 0 and you DECremented 1 from it F1 would equal -1, minus one.
  90.  
  91. Now if you have understood this chapter so far you may be thinking what if
  92. I wanted to DECrement more than one off of F1 or INC more than one?
  93. Well you could of course do this,
  94.  
  95. F1=10
  96. DEC F1
  97. DEC F1
  98. DEC F1
  99. DEC F1
  100.  
  101. This would leave F1 equalling 6, not very pretty and it`s time consuming 
  102. isn`t it? O.k how about this,
  103.  
  104. F1=10   : REM Make our variable (or counter if you like) equal 10
  105. F1=F1-4 : REM Make our counter equal our counter-4, F1 now equals 6
  106.           REM 10=10-4
  107. or 
  108.  
  109. F1=10
  110. F1=F1+4 : REM F1 now equals 14
  111.  
  112.  
  113. which is a lot shorter/neater and easier to understand, there is another
  114. way using ADD var,number and ADD var,-number  commands but you have enough to
  115. cope with at the moment. 
  116.  
  117. Getting back to WHY we would want a number to be represented by a letter!
  118. The reason is, it`s basically the only way to manipulate numbers, You wont
  119. find many programs written in ANY language that do not use variables.
  120. Check out chapter 4 in your Amos manual for a very good description of 
  121. variables for more information on the whys and wherefores of variables.
  122.  
  123. Now load EXAMPLE3.Amos and experiment.
  124.  
  125.  
  126.  
  127. End of chapter three.
  128.   
  129.